package util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.NumberFormat;

public class StdinReader {

	static InputStreamReader converter = new InputStreamReader(System.in);
	static BufferedReader in = new BufferedReader(converter);

	// Read a String from standard system input
	public static String getString() {
		try {
			return in.readLine();
		} catch (Exception e) {
			System.out.println("getString() exception, returning empty string");
			return "";
		}
	}

	// Read a char from standard system input
	public static char getChar() {
		String s = getString();
		if (s.length() >= 1)
			return s.charAt(0);
		else
			return '\n';
	}

	// Read a Number as a String from standard system input
	// Return the Number
	public static Number getNumber() {
		String numberString = getString();
		try {
			numberString = numberString.trim().toUpperCase();
			return NumberFormat.getInstance().parse(numberString);
		} catch (Exception e) {
			// if any exception occurs, just give a 0 back
			System.out.println("getNumber() exception, returning 0");
			return new Integer(0);
		}
	}

	// Read an integer from standard system input
	public static int getInt() {
		return getNumber().intValue();
	}

	// Read a float from standard system input
	public static float getFloat() {
		return getNumber().floatValue();
	}

	// Read a double from standard system input
	public static double getDouble() {
		return getNumber().doubleValue();
	}

}